/**
 * @description 创建 node 服务端
 * @author xfj
 */

const http = require('http')

// 处理请求
const serverHandler = (req, res) => {
  let data = ''
  req.on('data', (chunk) => {
    data += chunk
  })
  req.on('end', () => {
    data = JSON.parse(data)
    data.timesnap = new Date().getTime()
    res.end(JSON.stringify(data))
  })
}

// 通过 http.createServer 创建 node 服务端
const server = http.createServer(serverHandler)

server.listen(1234, () => {
  console.log('服务运行在 1234 端口...')
})
